using System;

namespace Commons.Models.Settings.Mappers
{
	public class DateTimeMapper : IMapper<string, DateTime?>
	{
		private const string DateTimeFormat = "dd/MM/yyyy HH:mm:ss zzz";
		private const string HHMMTTZZZ		= "           00:00:00 +00:00"; // TODO: SET FINAL TIME ZONE

		public DateTime? Map (string config)
		{
			if (config == null)
			{
				return null;
			}

			return DateTime.ParseExact(CompleteFormat(config), DateTimeFormat, null);
		}

		private string CompleteFormat (string dateString)
		{
			if (dateString.Length < HHMMTTZZZ.Length)
			{
				return dateString + HHMMTTZZZ.Substring(dateString.Length);
			}
			else
			{
				return dateString;
			}
		}
	}
}

